import Wechat from "@/utils/wechat.js";
export default {
	data() {
		return {
			uid:0,
			nickname:'',
			avatar:'',
			is_super_admin:0,
		}
	},
	methods: {
		async getApiUserinfo(e) {
			 this.$refs.wechat_login.saveShowStatus(true,true);
		},
		openUrl(type)
		{
			var url = '';
			switch(type)
			{
				case 'statistics-list':
					url = '/pages/member/statistics/list-all';
					break;
			}
			this.$api.navigateTo(url);
				
		},
		wechatRegister(){
			var loginStatus = this.$api.checkLogin();
			if(loginStatus == false)
			{
				this.uid = 0;
				this.username = '';
			}else{
				this.getUserInfo();
			}
		},
		uidCopy(){
			var _this = this;
			var uid = this.uid?this.uid.toString():'';
			if(uid)
			{
				uni.setClipboardData({
					data:uid,
					success: function () {
						_this.$api.msg('复制成功');
					}
				});
			}
		},
		goLogin(){
			if(this.uid > 0)
			 {
				 return ;
			 }
			 this.$refs.wechat_login.saveShowStatus(true);
		},
		getUserInfo(){
			var _this = this;
			_this.$http.post('User/getUserInfo').then(res=>{
				if(res.code == 1)
				{
					var userInfo = res.data.userInfo;
					if(userInfo)
					{
						_this.$api.checkUserInfo('set',userInfo);
					}
					_this.uid = userInfo.id;
					_this.nickname = userInfo.nickname;
					_this.avatar = userInfo.avatar;
					//_this.is_super_admin = userInfo.is_super_admin;
				}
			})
		}
	},
	onShow(){
		var _this = this;
		var loginStatus = _this.$api.checkLogin();
		if(loginStatus == false)
		{
			_this.uid = 0;
			_this.username = '';
		}else{
			_this.getUserInfo();
		}
	},
	onShareAppMessage(e)
	{
		var userInfo = this.$api.checkUserInfo();
		var nickname = userInfo.nickname?userInfo.nickname:'';
		var imageUrl = this.$api.getSystemConfig('base.group_share_bg');
		var obj =  {
		    title: nickname+'推荐您使用'+this.$api.getSystemConfig('wxMiniProgram.xcx_name'),
		    path: '/pages/index/member'
		}
		if(imageUrl)
		{
			obj.imageUrl = imageUrl;
		}
		return obj;
	}
}